//
//  LCWVisitorView.swift
//  MyWB
//
//  Created by 李成万 on 16/6/25.
//  Copyright © 2016年 李成万. All rights reserved.
//

import UIKit
import SnapKit

class LCWVisitorView: UIView {

    var closure:(()->())?
    
    //创建控件
    lazy var rotateImage = UIImageView(imageName: "visitordiscover_feed_image_smallicon")
    
    private lazy var maskImage = UIImageView(imageName: "visitordiscover_feed_mask_smallicon")
    
    private lazy var iconImage = UIImageView(imageName: "visitordiscover_feed_image_house")
    
    lazy var loginBtn : UIButton = {
       let btn = UIButton()
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: .Normal)
        btn.setTitle("登录", forState: .Normal)
        btn.setTitleColor(ThemeColor, forState: .Normal)
        btn.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
        
        return btn
    }()
    
    lazy var registerBtn : UIButton = {
        let btn = UIButton()
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: .Normal)
        btn.setTitle("注册", forState: .Normal)
        btn.setTitleColor(ThemeColor, forState: .Normal)
        btn.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
        
        return btn
    }()
    
    private lazy var messageLabel:UILabel = {
        let label = UILabel()
        
        label.text = "这是首页界面"
        label.textColor = ThemeColor
        
        label.textAlignment = .Center
        
        label.numberOfLines = 0
        
        label.font = UIFont.systemFontOfSize(15)
        return label
    }()
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        addSubview(rotateImage)
        addSubview(maskImage)
        addSubview(iconImage)
        addSubview(loginBtn)
        addSubview(registerBtn)
        addSubview(messageLabel)
        
        rotateImage.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        
        maskImage.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        
        iconImage.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(224)
            make.height.equalTo(36)
            make.top.equalTo(maskImage.snp_bottom).offset(16)
            make.centerX.equalTo(self)
        }
        
        loginBtn.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 100, height: 36))
            make.leading.equalTo(messageLabel)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
        }
        registerBtn.snp_makeConstraints { (make) -> Void in
            
            make.size.equalTo(CGSize(width: 100, height: 36))
            make.trailing.equalTo(messageLabel)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
        }
    }
    
    
    func setDIfferentMessage(message:String?,imageName:String?){
        
        if let oMessage = message, let oImageName = imageName{
            messageLabel.text = oMessage
            iconImage.image = UIImage(named: oImageName)
            
        }
        
    }
    
    func startAnimation(){
        let ani = CABasicAnimation(keyPath: "transform.rotation")
        ani.duration = 10
        ani.repeatCount = MAXFLOAT
        ani.toValue = M_PI * 2
        ani.removedOnCompletion = false
        
        rotateImage.layer.addAnimation(ani, forKey: nil)
        
    }
    
    func login(){
        closure?()
    }
}
